// Fill out your copyright notice in the Description page of Project Settings.
//#include "LuaWidgetFactory.h"
#include "LuaWidgetFactory.h"
#include "Kismet2/KismetEditorUtilities.h"
#include "Templates/Casts.h"
#include "Components/Widget.h"
#include "WidgetBlueprint.h"
#include "UMGEditorProjectSettings.h"
#include "BaseWidgetBlueprint.h"
#include "SGame/UMG/LuaUserWidget.h"
#include "Factories/Factory.h"
//#include <SGame/UMG/LuaUserWidget.h>




ULuaWidgetFactory::ULuaWidgetFactory(const FObjectInitializer& InObject):Super(InObject)
{
	bCreateNew = true;
	bEditAfterNew = true;
	SupportedClass = UWidgetBlueprint::StaticClass();
}

UObject* ULuaWidgetFactory::FactoryCreateNew(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
	UWidgetBlueprint* BP = CastChecked<UWidgetBlueprint>(FKismetEditorUtilities::CreateBlueprint(

		ULuaUserWidget::StaticClass(),
		InParent,
		InName,
		BPTYPE_Normal,
		UWidgetBlueprint::StaticClass(),
		UWidgetBlueprintGeneratedClass::StaticClass()));
	/*BP->WidgetTree->RootWidget == nullptr;*/
	if (BP->WidgetTree->RootWidget==nullptr)
	{
		if (TSubclassOf<UPanelWidget> RootWidgetClass=GetDefault<UUMGEditorProjectSettings>()->DefaultRootWidget)
		{
			UWidget* Root = BP->WidgetTree->ConstructWidget<UWidget>(RootWidgetClass);
			BP->WidgetTree->RootWidget = Root;
		}
	}
	return BP;
}
